package com.rutas.java;

import java.util.ArrayList;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class CapaPath extends Overlay {
	
	private ArrayList<GeoPoint> listaCoord = new ArrayList<GeoPoint>();
	private Paint pincel;
	
	public CapaPath(final ArrayList<GeoPoint> vectorPuntos, int dist){
		listaCoord = vectorPuntos;
		pincel = new Paint();
		//pincel.setAntiAlias(true);
		pincel.setStrokeWidth(3);
		if (dist > 50)
			pincel.setColor(Color.RED);
		else if (dist < 10)
			pincel.setColor(Color.GREEN);
		else 
			pincel.setColor(Color.YELLOW);
		
		pincel.setAlpha(100);
	}
	
	@Override
	public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow){
		
		//hace dos iteraciones, una cuando shadow es true y otra con shadow false		
		if (!shadow) {
			int tam = listaCoord.size();
			Projection proyeccion = mapView.getProjection();
			Point pixel = new Point();
			proyeccion.toPixels(listaCoord.get(0), pixel);
			for (int i = 1; i < tam; i++){
				Point pixel2 = new Point();
				//proyeccion.toPixels(listaCoord.get(i - 1), pixel);
				proyeccion.toPixels(listaCoord.get(i), pixel2);
				if (!pixel.equals(pixel2)){
					canvas.drawLine(pixel.x, pixel.y, pixel2.x, pixel2.y, pincel);
					pixel = pixel2;
				}
			}
		}
	}
}
